<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-form ref="form" :model="s_part" :rules="rules" label-width="100px" id="mvcfm">
          <el-button @click="gotoPage('/mes/certificate/AddCritical?'+vueparams+'')" type='success' size="mini"><i class='fa fa-plus'></i>增加关键件</el-button>
          <el-button @click="d_batch_part('')" :disabled="multiple" type='success' size="mini"><i class='fa fa-check'></i>批量删除</el-button>
          <el-button @click="u_relation('&part_relation=1')" type='success' size="mini"><i class='fa fa-check'></i>设置非全适用</el-button>
          <el-button @click="u_relation('&part_relation=2')" type='success' size="mini"><i class='fa fa-check'></i>设置全适用</el-button>
          <div class="form-unit">
            <span class="mvc-title-left"> 关键件列表 </span>
          </div>
          <el-table :data="s_part" @selection-change="handleSelectionChange">
            <el-table-column label="操作" align="center" width='100' type=''>
              <template slot-scope="scope">
                <el-dropdown trigger="click">
                  <span class="el-dropdown-link">操作<i class="el-icon-arrow-down el-icon--right"></i></span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-link @click="d_part('&CMIDpart_id='+scope.row.part_id+'')">删除</el-link>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
            <el-table-column label="#" align="center" type='selection'>
            </el-table-column>
            <el-table-column label="#" align="center" type='index'>
            </el-table-column>
            <el-table-column label="适用性" prop="part_relation">
              <template slot-scope="scope">
                {{getValueName("非全适用=1,全适用=2",scope.row.part_relation)}}
              </template>
            </el-table-column>
            <el-table-column label="类别" prop="part_type">
              <template slot-scope="scope">
                {{getValueName("A类=1,B类=2",scope.row.part_type)}}
              </template>
            </el-table-column>
            <el-table-column label="证书号" prop="part_num">
            </el-table-column>
            <el-table-column label="名称" prop="part_name">
              <template slot-scope="scope">
                {{scope.row.part_name}}
              </template>
            </el-table-column>
            <el-table-column label="型号" prop="part_model">
            </el-table-column>
            <el-table-column label="规格" prop="part_norm">
            </el-table-column>
            <el-table-column label="供应商" prop="client_name">
            </el-table-column>
            <el-table-column label="生产厂家" prop="enterprise">
            </el-table-column>
            <el-table-column label="增加时间" prop="entered">
              <template slot-scope="scope">
                {{getDateTimeString(scope.row,'entered')}}
              </template>
            </el-table-column>
          </el-table>
          <pagination v-show="total>0" :total="total" :limit.sync="pageSize" @pagination="getPage" />
        </el-form>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'关键件'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  import request from '@/utils/request'
  export default {
    name: 'Critical',
    components: {},
    props: ['popparams'],
    data() {
      return {
        vueparams: this.getVUEParams(""),
        s_part: [],
        loading: false,
        Container: null,
        elcheck: [],
        multiple: true,
        rules: {}
      }
    },
    created() {
      this.getData();
      this.loadContainerMenu({
        pid: "018E412E935E4B3EB6DF631BB3B46A50",
        name: "客户右菜单类型",
        selected: "关键件"
      }, 'Container', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/certificate/CertificateAction/critical?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      d_part(_params) {
        request({
          method: 'post',
          url: '/xcapi/VUEAction/mes/certificate/CertificateAction/d_part?' + _params + this.vueparams,
          data: this.postData()
        }).then(data => {
          this.$router.replace("/redirect" + this.$route.fullPath);
          this.msgSuccess(data.msg);
        })
      },
      d_batch_part(_params) {
        this.$confirm("确认批量删除", "警告").then(() => {
          request({
            method: 'post',
            url: '/xcapi/VUEAction/mes/certificate/CertificateAction/d_batch_part?' + _params + this.vueparams,
            data: this.postData()
          }).then(data => {
            this.$router.replace("/redirect" + this.$route.fullPath);
            this.msgSuccess(data.msg);
          })
        });
      },
      u_relation(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/mes/certificate/CertificateAction/u_relation?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.$router.replace("/redirect" + this.$route.fullPath);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      handleSelectionChange(selection) {
        this.elcheck = selection.map(item => item["part_id"]);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
    },
  }
</script>
